<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-4-16
 * Time: 上午10:25
 */

if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}
loadcache('plugin');
$set= $_G['cache']['plugin']['iExam'];
require_once "function.php";
if($_POST['formhash'] == formhash()){
	if($_POST['apply_action'] == 'Add' || $_POST['apply_action'] == 'Edit'){
		$post = array(
			'upid'          => $_POST['upid'],
			'catname'       => $_POST['catname'],
			'displayorder' => $_POST['displayorder'],
			'weight'        => $_POST['weight'],
			'description'   => $_POST['description']
		);
	}
	if($_POST['apply_action'] == 'Add'){
		$insertID = DB::insert('plugin_iexam_category', $post, 1);
		cpmsg("新增考试分类提交成功！", "action=plugins&operation=config&do=".$pluginid."&identifier=iExam&pmod=category", "succeed");
	}elseif($_POST['apply_action'] == 'Edit' && !is_null($_POST['catid'])){
		DB::update('plugin_iexam_category', $post, array('catid' => $_POST['catid']));
		cpmsg("新增考试分类提交成功！", "action=plugins&operation=config&do=".$pluginid."&identifier=iExam&pmod=category", "succeed");
	}elseif($_POST['apply_action'] == 'Del' && !is_null($_POST['catid'])){
		DB::delete('plugin_iexam_category'," catid = ".$_POST['catid']);
	}
}else{
	$category = categories();
	$nodes = json_encode($category['nodes']);
	include template('iexam:category');
}

